package org.example.intercepter;

import org.example.domain.*;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
    public boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception {
        HttpSession httpSession = request.getSession();
        Teacher teacher = (Teacher) httpSession.getAttribute("loginTeacher");
        Student student = (Student) httpSession.getAttribute("loginStudent");
        if (teacher==null&&student==null){
            //因为项目结构问题 导致了一个spring容器管理了两个项目 有很多请求不能重复
            //学生和老师的超时页面一致
            request.getRequestDispatcher("/timeoutT").forward(request,response);
            return false;
        }
        return true;
    }
}
